package com.adjy.pathbuilders.screens;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;


import com.adjy.pathbuilders.rendering.GameCanvas;
import com.adjy.pathbuilders.rendering.loading.AnimationFactory;

public class SplashScreen implements GameScreen {
	
	private Paint  backPaint;
	private AnimationFactory factory;
	private long time;
	
	public SplashScreen(AnimationFactory factory) {
		backPaint = new Paint();
		backPaint.setColor(Color.WHITE);
		this.factory = factory;

		this.time = System.currentTimeMillis();
		
	}
	
	private void showAnimation(GameCanvas mcanvas){
		
		Bitmap caixa = factory.getImage("caixa");
		if (System.currentTimeMillis() - this.time > 1000)
			mcanvas.drawBitmapWithConversion(caixa, 270, 380);
		
		if (System.currentTimeMillis() - this.time > 2000)
			mcanvas.drawBitmapWithConversion(caixa, 330, 380);
		
		if (System.currentTimeMillis() - this.time > 3000)
			mcanvas.drawBitmapWithConversion(caixa, 390, 380);
		
		if (System.currentTimeMillis() - this.time > 4000)
			mcanvas.drawBitmapWithConversion(caixa, 450, 380);
		
		mcanvas.drawBitmapWithConversion(factory.getImage("boneco"),
				140+(System.currentTimeMillis() - this.time)/14, 300);
		
	}
	
	public Boolean loading(){
		if (System.currentTimeMillis() - this.time < 5000)
			return true;
	    return false;
	}

	@Override
	public void load() {
		factory.loadImages("splash_bg","caixa","boneco");
	}

	@Override
	public void release() {
		factory.releaseImages("splash_bg","caixa","boneco");
	}

	@Override
	public void input(MotionEvent event) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void render(GameCanvas mcanvas, float timeElapsed) {
		mcanvas.drawBackground(factory.getImage("splash_bg"));	
		
		showAnimation(mcanvas);
	}

	@Override
	public void step(float timePassed) {
		// TODO Auto-generated method stub
		
	}

}
